﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ColorPane
{
    static public class TextBoxTool
    {
        private const Int32 EM_SETCUEBANNER = 0x1501;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern private Int32 SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, [MarshalAs(UnmanagedType.LPWStr)]String lParam);

        /// <summary>
        /// 设置水印
        /// </summary>
        /// <param name="textbox">要设置的TextBox控件</param>
        /// <param name="wartermark">要设置的水印文本</param>
        static public void SetWartermark(this TextBox textbox, String wartermark)
        {
            SendMessage(textbox.Handle, EM_SETCUEBANNER, 0, wartermark);
        }

        /// <summary>
        /// 清除水印
        /// </summary>
        /// <param name="textbox">要设置的TextBox控件</param>        
        static public void ClearWartermark(this TextBox textbox)
        {
            SendMessage(textbox.Handle, EM_SETCUEBANNER, 0, String.Empty);
        }
    }
}
